package edu.lsnu.equipment_management_system.service.impl;

import edu.lsnu.equipment_management_system.pojo.vo.sql_conditions.UserNoAndEquipmentNoVo;
import edu.lsnu.equipment_management_system.service.UpdateEquipmentUseRecordTableEndDateService;
import edu.lsnu.equipment_management_system.mapper.update.UpdateEquipmentUseRecordTableEndDateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author mzy
 * @Description 设备的使用者改变
 * @date 2018/11/25
 */
@Service
@Transactional(propagation= Propagation.REQUIRED)
public class UpdateEquipmentUseRecordTableEndDateServiceImpl implements UpdateEquipmentUseRecordTableEndDateService {
    @Autowired
    UpdateEquipmentUseRecordTableEndDateMapper updateEquipmentUseRecordTableEndDateMapper;
    /**
     * @Description 为上一条使用记录加上结束时间
     * @author mzy
     * @time 2018-11-25
     * @see
     * @return   boolean
     * @params  [equipmentNo, userNo]
     */
    @Override
    public boolean updateEndTimeToPreviousEquipmentUseRecord(String equipmentNo, String userNo) {
        UserNoAndEquipmentNoVo userNoAndEquipmentNoVo = new UserNoAndEquipmentNoVo();
        userNoAndEquipmentNoVo.setEquipmentNo(equipmentNo);
        userNoAndEquipmentNoVo.setUserNo(userNo);

        int count = updateEquipmentUseRecordTableEndDateMapper.updateEndTimeToPreviousEquipmentUseRecord(userNoAndEquipmentNoVo);
        if (0 == count) {
            return false;
        }
        return true;
    }
}
